/**
 * related to addShop2.ui
 * 
 * @Author : chenglm
 * @Timestamp : 2016-12-17
 */
var page = sm("do_Page");
var app = sm("do_App");
var nf = sm("do_Notification");
var root = ui("$");
var global = deviceone.sm("do_Global");
var imgTool = require("helper/picture");
var helperOpen = require("helper/open");
var linearLayout_main = ui("linearLayout_main");
var hashdata = mm("do_HashData");
var aLayoutCamera = ui("aLayout_camera");
var textFieldName = ui("textField_name");
var textBoxResume = ui("textBox_resume");

var jsonData = {};
//andriod返回键
page.on("back", function() {
    app.closePage();
});

/* 头部 */
var headerAout = ui("layoutHead");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var header = ui("header");
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
var labelTitle = ui(addheader+".labelTitle");
labelTitle.text='填写资料';
headerLeft.on("touch", function() {
    app.closePage();
});
//右上角
var headerRight = ui(addheader+".headerRight");
var labelNext = ui(addheader+".labelNext");
labelNext.visible = true;
labelNext.text = "下一步";
headerRight.on("touch", function() {
	page.hideKeyboard();
	var shopLogoPath = aLayoutCamera.source;
	var shopName = textFieldName.text;
	var shopResume = textBoxResume.text;
	if(shopLogoPath=="" || shopLogoPath ==null || shopLogoPath.indexOf("source://")>-1){
		nf.toast("请添加图片");
		return;
	}
	if(shopName=="" || shopName ==null){
		nf.toast("请填写店铺名称");
		return;
	}else{
		if (shopName.length > 16) {
			nf.toast("名称不能超过16个字符");
			return;
		}
		var reg = /^[a-z0-9A-Z\u4e00-\u9fa5]+$/;
		if(!shopName.match(reg)){
			nf.toast("名称只能包含包含字母、数字和汉字");
			return;
		}
	}
	if(shopResume=="" || shopResume ==null){
		nf.toast("请填写店铺简介");
		return;
	}else if(shopResume.length > 100){
		nf.toast("简介不能超过100个字符");
		return;
	}
	jsonData.name = shopName;
	jsonData.resume = shopResume;
	jsonData.logo = shopLogoPath;
	helperOpen.open("source://view/qshop/manage/shop/addShop3.ui",jsonData);
});

//点击背景隐藏输入键盘
root.on("touch",function(){
	page.hideKeyboard();
})

//点击-相机
aLayoutCamera.on("touch", function(data, e) {
	page.hideKeyboard();
	imgTool.imgCut(selectImgBack);
});

function selectImgBack(imgList){
	aLayoutCamera.source=imgList[0];
}